package com.pince.lifcycleliveav.pushplayer

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent


/**
 * 监听activity管理推流器的生命周期
 */
open class LifecycleTXPusher : TXPushPlayerExt, LifecycleObserver {

    constructor(context: Context) : super(context)

    constructor(context: Context, mAttributeSet: AttributeSet?) : super(context, mAttributeSet)

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun onResume(activity: LifecycleOwner) {
        Log.d("TXPusher","ON_RESUME")
        onActivityResume()
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    fun onPause(activity: LifecycleOwner) {
        Log.d("TXPusher","ON_PAUSE")
        onActivityPause()
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    fun onDestroy() {
        Log.d("TXPusher","ON_DESTROY")
        stopRtmpPublish()
    }


}